package org.langcom.logic;

import java.io.PrintStream;


public class PrintUtils {

	private static final String NODE = " |_";//$NON-NLS-1$

	public static void printLogic(PrintStream stream,ILogic logic) {
		stream.println(logic.toString() + "  " + Thread.currentThread().getStackTrace()[3]); //$NON-NLS-1$
		if (((ICompositeLogic) logic).getChildren().size() > 0) {
			stream.println(" | ");//$NON-NLS-1$
			for (ILogic child : ((ICompositeLogic) logic).getChildren()) {
				stream.print(NODE);
				printChild(stream,child);
			}
		}
		stream.println("  ");//$NON-NLS-1$
	}
	
	private static void printChild(PrintStream stream,ILogic child) {
		stream.println(child.toString());
		if ((child instanceof ICompositeLogic)
			&& (((ICompositeLogic) child).getChildren().size() > 0)) {
			stream.println(" | ");//$NON-NLS-1$
			for (ILogic logic : ((ICompositeLogic) child).getChildren()) {
				stream.print(NODE);
				printChild(stream,logic);
			}
		}
		stream.println("  ");//$NON-NLS-1$
	}
}
